package com.lwq.controller.system;

import com.lwq.annotation.PermissionController;
import com.lwq.annotation.PermissionInterface;
import com.lwq.annotation.RepeatSubmit;
import com.lwq.controller.BaseController;
import com.lwq.model.Dto;
import com.lwq.model.Dtos;
import com.lwq.model.Result;
import com.lwq.model.system.SysMenu;
import com.lwq.service.system.MenuService;
import com.lwq.util.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2021/6/12
 */
@PermissionController(type="system")
@RestController
public class MenuController extends BaseController {

    @Autowired
    private MenuService service;

    @GetMapping("/menu/list")
    @PermissionInterface(name="查询菜单", code="menu.query")
    public TableDataInfo list(){
        Dto dto = Dtos.newDto(request);
        startPage();
        return getDataTable(service.queryList(dto));
    }

    @GetMapping("/menu/dropList")
    @PermissionInterface(name="查询菜单", code="menu.query")
    public Result listNoRecursion(){
        return Result.ok(service.queryListNoRecursion());
    }

    @PostMapping("/menu")
    @RepeatSubmit
    @PermissionInterface(name="新增菜单", code="menu.add")
    public Result add(@RequestBody @Valid SysMenu sysMenu){
        service.add(sysMenu);
        return Result.ok();
    }

    @PutMapping("/menu")
    @RepeatSubmit
    @PermissionInterface(name="修改菜单", code="menu.update")
    public Result update(@RequestBody @Valid SysMenu menu){
        service.update(menu);
        return Result.ok();
    }

    @DeleteMapping("/menu/{id}")
    @PermissionInterface(name="删除菜单", code="menu.remove")
    public Result remove(@PathVariable Long id){
        service.del(id);
        return Result.ok();
    }
}
